#ifndef _PARTHUS_LMP_CONST_
#define _PARTHUS_LMP_CONST_

/**************************************************************************
 * MODULE NAME:    lmp_const.h
 * PROJECT CODE:    BlueStream
 * DESCRIPTION:    Constants for LMP Objects, Message Opcodes, PDU lengths etc..
 * AUTHOR:         Gary Fleming
 * DATE:           23 July 99
 *
 *
 * LICENSE:
 *     This source code is copyright (c) 1999-2004 Ceva Inc.
 *     All rights reserved.
 *
 * REVISION HISTORY:
 *    V1.0     xx xxx 1999 -   gf       - Initial Version
 *
 * SOURCE CONTROL:  $Id: lmp_const.h,v 1.24 2009/11/23 05:39:48 tianwq Exp $
 *
 **************************************************************************/

/*********************************************************************
 * LMP MESSAGE OPCODES
 * -------------------
 *  LMP Message Opcodes as per Ver 1.1 of Bluetooth SIG Specification
 ********************************************************************/

#define NO_OPERATION                                     0
#define LMP_NAME_REQ                                     1
#define LMP_NAME_RES                                     2
#define LMP_ACCEPTED                                     3
#define LMP_NOT_ACCEPTED                                 4
#define LMP_CLKOFFSET_REQ                                5
#define LMP_CLKOFFSET_RES                                6
#define LMP_DETACH                                       7
#define LMP_IN_RAND                                      8
#define LMP_COMB_KEY                                     9
#define LMP_UNIT_KEY                                    10
#define LMP_AU_RAND                                     11
#define LMP_SRES                                        12
#define LMP_TEMP_RAND                                   13
#define LMP_TEMP_KEY                                    14
#define LMP_ENCRYPTION_MODE_REQ                         15
#define LMP_ENCRYPTION_KEY_SIZE_REQ                     16
#define LMP_START_ENCRYPTION_REQ                        17
#define LMP_STOP_ENCRYPTION_REQ                         18
#define LMP_SWITCH_REQ                                  19
#define LMP_HOLD                                        20
#define LMP_HOLD_REQ                                    21
#define LMP_SNIFF                                       22  /* Removed from Spec */
#define LMP_SNIFF_REQ                                   23
#define LMP_UNSNIFF_REQ                                 24
#define LMP_PARK_REQ                                    25
#define LMP_SET_BROADCAST_SCAN_WINDOW                   27
#define LMP_MODIFY_BEACON                               28
#define LMP_UNPARK_BD_ADDR_REQ                          29
#define LMP_UNPARK_PM_ADDR_REQ                          30
#define LMP_INCR_POWER_REQ                              31
#define LMP_DECR_POWER_REQ                              32
#define LMP_MAX_POWER                                   33
#define LMP_MIN_POWER                                   34
#define LMP_AUTO_RATE                                   35
#define LMP_PREFERRED_RATE                              36
#define LMP_VERSION_REQ                                 37
#define LMP_VERSION_RES                                 38
#define LMP_FEATURES_REQ                                39
#define LMP_FEATURES_RES                                40
#define LMP_QUALITY_OF_SERVICE                          41
#define LMP_QUALITY_OF_SERVICE_REQ                      42
#define LMP_SCO_LINK_REQ                                43
#define LMP_REMOVE_SCO_LINK_REQ                         44
#define LMP_MAX_SLOT                                    45
#define LMP_MAX_SLOT_REQ                                46
#define LMP_TIMING_ACCURACY_REQ                         47
#define LMP_TIMING_ACCURACY_RES                         48
#define LMP_SETUP_COMPLETE                              49
#define LMP_USE_SEMI_PERMANENT_KEY                      50
#define LMP_HOST_CONNECTION_REQ                         51
#define LMP_SLOT_OFFSET                                 52
#define LMP_PAGE_MODE_REQ                               53
#define LMP_PAGE_SCAN_MODE_REQ                          54
#define LMP_SUPERVISION_TIMEOUT                         55
#define LMP_TEST_ACTIVATE                               56
#define LMP_TEST_CONTROL                                57
#define LMP_ENCRYPTION_KEY_SIZE_MASK_REQ                58
#define LMP_ENCRYPTION_KEY_SIZE_MASK_RES                59
#define LMP_SET_AFH                                     60
#define LMP_ENCAPSULATED_HEADER                         61
#define LMP_ENCAPSULATED_PAYLOAD                        62
#define LMP_SIMPLE_PAIRING_CONFIRM                      63
#define LMP_SIMPLE_PAIRING_NUMBER                       64
#define LMP_DHKEY_CHECK                                 65

#define LMP_ESCAPE_1_OPCODE                             124
#define LMP_ESCAPE_2_OPCODE                             125
#define LMP_ESCAPE_3_OPCODE                             126
#define LMP_ESCAPE_4_OPCODE                             127

/*
 * Extension 1 (124) opcodes
 */
/* None */

/*
 * Extension 2 (125) opcodes
 */
/* None */

/*
 * Extension 3 (126) opcodes
 */
/* None */

/*
 * Extension 4 (127) opcodes
 */
/*
 * The ENCODE_ESC_OPCODE allows for the opcodes to be extended to
 * include the escape opcode if necessary
 */
#define ENCODE_ESC_OPCODE(escape_opcode, extended_op_code)  \
    ((escape_opcode<<8)+extended_op_code)
#define LMP_ACCEPTED_EXT                   ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE, 1)
#define LMP_NOT_ACCEPTED_EXT               ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE, 2)
#define LMP_FEATURES_REQ_EXT               ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE, 3)
#define LMP_FEATURES_RES_EXT               ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE, 4)
#define LMP_SCATTER_REQ                    ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE, 5)
#define LMP_UNSCATTER_REQ                  ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE, 6)
#define LMP_SET_SUBRATE                    ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE, 7)
#define LMP_SCATTER_ALGORITHMS_REQ         ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE, 8)
#define LMP_SCATTER_ALGORITHMS_RES         ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE, 9)
#define LMP_PP_EXTENSION_REQ               ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE,10)
#define LMP_PACKET_TYPE_TABLE_REQ          ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE,11)
#define LMP_ESCO_LINK_REQ                  ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE,12)
#define LMP_REMOVE_ESCO_LINK_REQ           ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE,13)
#define LMP_CHANNEL_CLASSIFICATION_REQ     ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE,16)
#define LMP_CHANNEL_CLASSIFICATION         ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE,17)
#define LMP_ALIAS_ADDRESS                  ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE,18)
#define LMP_ACTIVE_ADDRESS                 ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE,19)
#define LMP_FIXED_ADDRESS                  ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE,20)
#define LMP_SNIFF_SUBRATING_REQ            ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE,21)
#define LMP_SNIFF_SUBRATING_RES            ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE,22)
#define LMP_PAUSE_ENCRYPTION_REQ           ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE,23)
#define LMP_RESUME_ENCRYPTION_REQ          ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE,24)
#define LMP_IO_CAPABILITY_REQ              ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE,25)
#define LMP_IO_CAPABILITY_RES              ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE,26)
#define LMP_NUMERIC_COMPARISON_FAILED      ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE,27)
#define LMP_PASSKEY_FAILED                 ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE,28)
#define LMP_OOB_FAILED                     ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE,29)
#define LMP_KEYPRESS_NOTIFICATION          ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE,30)
#define LMP_POWER_CONTROL_REQ              ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE,31)
#define LMP_POWER_CONTROL_RES              ENCODE_ESC_OPCODE(LMP_ESCAPE_4_OPCODE,32)

/********************************************************
 * Default Timer Values, as for specification
 ********************************************************/

#define PRH_DEFAULT_ACCEPT_TIMEOUT          0x1FA0   /* 5.06 Seconds */
#define PRH_DEFAULT_PAGE_TIMEOUT            0x2000   /* 5.12 Seconds */
#if(PRH_BS_CFG_SYS_HCI_V12_FUNCTIONALITY_SUPPORTED==1)
#define DEFAULT_INQUIRY_SCAN_INTERVAL       0x0800    /* 2.56 Seconds */
#else
#define DEFAULT_INQUIRY_SCAN_INTERVAL       0x0800   /* 1.28 Seconds */
#endif
#define DEFAULT_INQUIRY_SCAN_WINDOW         0x0012   /*      */
#define DEFAULT_PAGE_SCAN_INTERVAL          0x0800   /* 1.28 Seconds */
#define DEFAULT_PAGE_SCAN_WINDOW            0x0012   /*      */
#if BUILD_EMULATION==1
#define DEFAULT_T_POLL                           6
#else
#define DEFAULT_T_POLL                          40
#endif
#define DEFAULT_TRANS_INTERVAL                   0
#define MIN_INQUIRY_PERIOD				   (4<<11)

#define DEFAULT_SUPERVISION_TIMEOUT         0x7D00   /*20.00 Seconds */
#define DEFAULT_FLUSH_TIMEOUT               0x0000
#define PRH_DEFAULT_LMP_TRANSACTION_TIMEOUT 0xbb80   /*30.00 Seconds */
#define DEFAULT_NBC                         0x0002   /* 2 Broadcast  */

/********************************************************
 * CONFIGURATION CONSTANTS
 ********************************************************/

/* #1701: current implementation contraint DACC >= TBRP+6 */
#define _LM_MIN_TBRP_DACC_GUARD             6

/* #2292: next beacon instant - end access window > 2 frames */
#define _LM_MIN_BEACON_INSTANT_GUARD        4

/********************************************************
 * Indexs for LMP Events to the higher layers
 ********************************************************/
#define _LM_REMOTE_SUPORTED_FEATURES_CFM                  0x00
#define _LM_REMOTE_VERSION_CFM                            0x01
#define _LM_CONNECT_IND                                   0x02
#define _LM_CONNECT_CFM                                   0x03
#define _LM_CONNECT_COMPLETE                              0x04
#define _LM_DISCONNECT_IND                                0x05
#define _LM_DISCONNECT_COMPLETE                           0x06
#define _LM_REMOTE_NAME_CFM                               0x07
#define _LM_ROLE_CHANGE_EVENT                             0x08
#define _LM_INQUIRY_RESULT_EVENT                          0x09
#define _LM_INQUIRY_COMPLETE_EVENT                        0x0a
#define _LM_READ_CLOCK_OFFSET_EVENT                       0x0b
#define _LM_RETURN_LINK_KEY_DB_EVENT                      0x0c
#define _LM_READ_REMOTE_SUPPORTED_FEATURES_COMPLETE_EVENT 0x0d
#define _LM_CONNECTION_PACKET_TYPE_CHANGED_EVENT          0x0f
#define _LM_INQUIRY_RESULT_WITH_RSSI_EVENT                0x10
#define _LM_READ_REMOTE_EXTENDED_FEATURES_COMPLETE_EVENT  0x11
#define _LM_INQUIRY_RESULT_WITH_RSSI_AND_EIR_EVENT        0x12
#define _LM_MAX_NUM_EVENTS                                0x13 /* Always ensure last event */


#define FEATURES_SIZE           8
#define MAX_KEY_SIZE            16
#define MAX_RANDOM_NUMBER       16
#define ROLE_TID                0
#define PEER_ROLE_TID           1

#define LMP_ENCAPSULATED_PAYLOAD_SIZE   0x10
#define ACTIVE_MODE             0x00
#define HOLD_MODE               0x01
#define SNIFF_MODE              0x02
#define PARK_MODE               0x03

#define MAX_LMP_OPCODE          57

#define LIAC_LAP                0x9E8B00

#define HCI_DM1 0x0008
#define HCI_DH1 0x0010
#define HCI_DM3 0x0400
#define HCI_DH3 0x0800
#define HCI_DM5 0x4000
#define HCI_DH5 0x8000

#define HCI_1_SLOT  (HCI_DM1 | HCI_DH1)
#define HCI_3_SLOT  (HCI_DM3 | HCI_DH3)
#define HCI_5_SLOT  (HCI_DM5 | HCI_DH5)

#define HCI_HIGH_RATE    ( HCI_DH1 | HCI_DH3 | HCI_DH5)
#define HCI_MEDIUM_RATE  ( HCI_DM1 | HCI_DM3 | HCI_DM5)

#if(PRH_BS_CFG_SYS_LMP_EDR_ACL_2_MBPS_MODE_SUPPORTED==1)
#define HCI__2DH1 0x0002
#define HCI__3DH1 0x0004
#define HCI__2DH3 0x0100
#define HCI__3DH3 0x0200
#define HCI__2DH5 0x1000
#define HCI__3DH5 0x2000

#define HCI_EDR_1_SLOT  (HCI__2DH1 | HCI__3DH1)
#define HCI_EDR_3_SLOT  (HCI__2DH3 | HCI__3DH3)
#define HCI_EDR_5_SLOT  (HCI__2DH5 | HCI__3DH5)

#define HCI_EDR_DM1_RATE    ( HCI_DM1)
#define HCI_EDR_2M_RATE  ( HCI__2DH1 | HCI__2DH3 | HCI__2DH5)
#define HCI_EDR_3M_RATE  ( HCI__3DH1 | HCI__3DH3 | HCI__3DH5)

#define HCI_EDR_ACL        (HCI_EDR_2M_RATE|HCI_EDR_3M_RATE)
#define HCI_GFSK_ACL       (HCI_5_SLOT|HCI_3_SLOT|HCI_DH1)

#endif
#define HCI_HV1     0x0020
#define HCI_HV2     0x0040
#define HCI_HV3     0x0080

#define HCI_SYN_HV1 0x0001
#define HCI_SYN_HV2 0x0002
#define HCI_SYN_HV3 0x0004
#define HCI_SYN_EV3 0x0008
#define HCI_SYN_EV4 0x0010
#define HCI_SYN_EV5 0x0020

#define HCI_GFSK_ESCO       (HCI_SYN_EV3|HCI_SYN_EV4|HCI_SYN_EV5)

/*
 * The HCI Accept Synchronous Connection (the
 * HCI Setup Synchronous Connection has nothing
 * to say on the matter. Normally they
 * are tied low if unused.. go figure :-)
 * command requires that the reserved bits are set
 * high...
 */
#define SYN_RESERVED_PACKET_TYPES 0xffc0

/*
 * Bitfields for indicating allocated  DSCOs
 */
#define LM_SCO_PACKET_HV1      0x00
#define LM_SCO_PACKET_HV2      0x01
#define LM_SCO_PACKET_HV3      0x02
#define LM_SCO_PACKET_HV4      0x03

#define LM_SCO_PACKET_POLLNULL 0x00
#define LM_SCO_PACKET_EV3      0x07
#define LM_SCO_PACKET_EV4      0x0C
#define LM_SCO_PACKET_EV5      0x0D

#if(PRH_BS_CFG_SYS_LMP_EDR_ESCO_2_MBPS_MODE_SUPPORTED==1)
#define LM_SCO_PACKET__2EV3    0x26
#define LM_SCO_PACKET__2EV5    0x2C
#define LM_SCO_PACKET__3EV3    0x37
#define LM_SCO_PACKET__3EV5    0x3D
#define HCI_SYN__2EV3          0x0040
#define HCI_SYN__3EV3          0x0080
#define HCI_SYN__2EV5          0x0100
#define HCI_SYN__3EV5          0x0200
#define HCI_EDR_SYN       (HCI_SYN__2EV3|HCI_SYN__3EV3|HCI_SYN__2EV5|HCI_SYN__3EV5)
#endif

#define LM_SCO_PACKET_INVALID 0xFF



#define LMP_SNIFF_ACTIVATION_PENDING    0x21
#define LMP_SNIFF_ACTIVE                0x22
#define LMP_SNIFF_INACTIVE              0x23

#define LMP_SNIFF_SUBRATING_PENDING                                   0x24
#define LMP_SNIFF_SUBRATING_ACTIVE                                    0x25
#define LMP_SNIFF_SUBRATING_W4_ACTIVE                                 0x26
#define LMP_SNIFF_SUBRATING_PAUSED_BY_SUPERVISION_TIMEOUT_CHANGE      0x27
#define LMP_SNIFF_SUBRATING_PAUSED_W4_ACK                             0x28
#define LMP_SNIFF_SUBRATING_PAUSED_BY_DATA                            0x29

#define LMP_BEACON_ACTIVE                          0x31
#define LMP_BEACON_INACTIVE                        0x32
#define LMP_ACCESS_WINDOW_ACTIVE                   0x33
#define LMP_N_POLL_AFTER_ACCESS_WINDOW             0x34
#define LMP_UNPARK_AFTER_ACCESS_WINDOW             0x35
#define LMP_BROADCAST_SCAN_WINDOW_EXTENSION_ACTIVE 0x36
#define LMP_W4_ACCESS_WINDOW                       0x37

#define MAX_NAME_FRAGMENT_SIZE     14

#define PRH_NO_BROADCAST            0x01
#define PRH_ACTIVE_BROADCAST        0x02
#define PRH_PICONET_BROADCAST       0x03

#define PRH_NO_TRAFFIC              0x00
#define PRH_BEST_EFFORT             0x01
#define PRH_GUARANTEED_SERVICE      0x02

#define PRH_NO_FLUSH_PENDING        0x00
#define PRH_INIT_FLUSH_PENDING      0x01
#define PRH_START_PKT_FLUSHED       0x02
#define PRH_QUEUE_FLUSH_PENDING     0x04

#define PRH_NO_UNPARK_PENDING       0x00
#define PRH_MASTER_INITIATED_UNPARK 0x01
#define PRH_SLAVE_INITIATED_UNPARK  0x02

#define PRH_ONE_SHOT_INQUIRY           1
#define PRH_PERIODIC_INQUIRY           2

#define PRH_NO_FLUSH                   0
#define PRH_LINK_BUFFER_FLUSH          1
#define PRH_PACKET_FLUSH               2
#define PRH_ENHANCED_FLUSH             3

#define PRH_FLUSH_IDLE                 0
#define PRH_W4_SCAN_FROM_SCHEDULAR     2
#define PRH_W4_FLUSH_TO_EXECUTE        4
#define PRH_W4_ACK                     8

#define FLUSH_PACKET_AUTOMATIC_ONLY         0x00
#define FLUSH_PACKET_ALL                          0xff

#define LINK_POLICY_NONE_ENABLED   0x00
#define LINK_POLICY_SWITCH_ENABLED 0x01
#define LINK_POLICY_HOLD_ENABLED   0x02
#define LINK_POLICY_SNIFF_ENABLED  0x04
#define LINK_POLICY_PARK_ENABLED   0x08

#define LINK_POLICY_AUTOMATIC_UNPARK_ENABLED 0x10
#define LINK_POLICY_AUTOMATIC_REHOLD_ENABLED 0x20


#define BT_SPEC_MAX_NAME_LENGTH     248

/* PRTH SPECIFIC DEBUG CONSTANTS */
#define PRTH_HW_ERROR_LMP_CH       0x01

#define MAX_NUM_LMP_PDUS              5
#define MAX_LMP_PDU_SIZE             20

/* Max time to service piconet */
#define PRH_BS_PICONET_SERVICE_TIME 100

/*
* Maximum number of frames the d_esco
* calculator will lookahead for clashes
* before assuming the new connection
* can be supported.
*/
#if(PRH_BS_CFG_SYS_LMP_EDR_ESCO_2_MBPS_MODE_SUPPORTED==1)
#define MAX_SUPPORTED_T_ESCO             108
#define MAX_NUM_ESCO_LMP_PARAMETER_SETS  7
#else
#define MAX_SUPPORTED_T_ESCO             36
#define MAX_NUM_ESCO_LMP_PARAMETER_SETS  3
#endif

#define MAX_D_ESCO_LOOKAHEAD_FRAMES      MAX_SUPPORTED_T_ESCO
#define MAX_NUM_D_ESCOS_IN_LIST (MAX_D_ESCO_LOOKAHEAD_FRAMES>>1)

#endif

